package com.example.demo.controller;

import com.example.demo.controller.data.ReturnData;
import com.example.demo.entity.Circle;
import com.example.demo.entity.CircleLike;
import com.example.demo.sevice.CircleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 圈子相关的接口控制类
 */
@RestController
@RequestMapping("/circle")
public class CircleController {
    @Resource
    CircleService circleService;

    //发布接口
    @PostMapping("/add")
    public ReturnData add(@RequestBody Circle circle, HttpServletRequest request) {
        String token = request.getHeader("token");
        return  circleService.add(circle,token);
    }

    /**
     * 圈子列表接口
     * @param page 页码
     * @param pageSize  每一页的长度 默认为10
     * @return
     */
    @GetMapping("/list")
    public ReturnData list(@RequestParam(defaultValue = "1")int page,
                           @RequestParam(defaultValue = "20") int pageSize,
                           HttpServletRequest request) {
        String token = request.getHeader("token");
        return  circleService.getList(page,pageSize,token);
    }

    /**
     * 获取当前登录用户发布的内容
     * @param page 页码，1 2 3 4
     * @param pageSize 每一页的大小 20
     * @param request
     * @return
     */
    @GetMapping("/myList")
    public ReturnData myList(@RequestParam(defaultValue = "1")int page,
                             @RequestParam(defaultValue = "20") int pageSize,
                             HttpServletRequest request) {
        String token = request.getHeader("token");
        //Alt+ENTER(回车)
        return  circleService.myList(page,pageSize,token);
    }

    /**
     * 点赞或者取消点赞接口
     * @param circleLike
     * @param request
     * @return
     */
    @PostMapping("/like")
    public ReturnData like(@RequestBody CircleLike circleLike, HttpServletRequest request) {
        String token = request.getHeader("token");
        return  circleService.like(circleLike,token);
    }

    /**
     * 获取某条圈子的点赞用户列表
     * @param circleId
     * @return
     */
    @GetMapping("/getLikeUsers")
    public ReturnData getLikeUsers(int circleId){
        return circleService.getLikeUsers(circleId);
    }

    @GetMapping("/myLikeList")
    public ReturnData myLikeList(@RequestParam(defaultValue = "1") int page,
                                 @RequestParam(defaultValue = "20") int pageSize,
                                 HttpServletRequest request) {
        String token = request.getHeader("token");
        //Alt+ENTER(回车)
        return circleService.myLikeList(page,pageSize,token);
    }

    /**
     * 删除圈子的接口
     * @param circle
     * @param request
     * @return
     */
    @PostMapping("/delete")
    public ReturnData delete(@RequestBody Circle circle,HttpServletRequest request){
        String token = request.getHeader("token");
        return circleService.delete(circle.getId(),token);
    }
}
